<% layout('/layout/default.html', {title: '主子表生成详情', libs: ['validate', 'icheck']}){ %>
<div class="main-content">
	<div class="card-header">
		<i class="fa fa-sitemap"></i>${testDataMain.isNewRecord?'新增主子表生成':'编辑主子表生成'}
	</div>
	<#form:form id="inputForm" model="${testDataMain}" action="${ctx}/test/testDataMain/save" method="post" class="form-horizontal">
		<div class="card-body">
			<#form:hidden path="id"/>
			<div class="row">
				<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
					<div class="form-group row">
						<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
						 归属用户：
						</label>
						<div class="col-lg-8 col-md-8 ">
							<#form:treeselect id="userId" name="user.id" value="${testDataMain.user.id!}" labelName="user.name"
									labelValue="${testDataMain.user.name!}" title="用户" url="/sys/office/treeData?type=3" cssClass="form-control-sm" notAllowSelectParent="true" />
						</div>
					</div>
				</div>
				<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
					<div class="form-group row">
						<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
						 归属部门：
						</label>
						<div class="col-lg-8 col-md-8 ">
							<#form:treeselect id="officeId" name="office.id" value="${testDataMain.office.id!}" labelName="office.name"
									labelValue="${testDataMain.office.name!}" title="部门" url="/sys/office/treeData?type=2" cssClass="form-control-sm" notAllowSelectParent="true" />
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
					<div class="form-group row">
						<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
						 归属区域：
						</label>
						<div class="col-lg-8 col-md-8 ">
							<#form:treeselect id="areaId" name="area.id" value="${testDataMain.area.id!}" labelName="area.name"
									labelValue="${testDataMain.area.name!}" title="区域" url="/sys/area/treeData" cssClass="form-control-sm" notAllowSelectParent="true" />
						</div>
					</div>
				</div>
				<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
					<div class="form-group row">
						<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
						 名称：
						</label>
						<div class="col-lg-8 col-md-8 ">
							<#form:input path="name"  maxlength="100" class="form-control form-control-sm "/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
					<div class="form-group row">
						<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
						 性别：
						</label>
						<div class="col-lg-8 col-md-8 ">
							<#form:input path="sex"  maxlength="1" class="form-control form-control-sm "/>
						</div>
					</div>
				</div>
				<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
					<div class="form-group row">
						<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
						 加入日期：
						</label>
						<div class="col-lg-8 col-md-8 ">
							<input id="inDate" type="text" name="inDate" maxlength="20" readonly="readonly" class="form-control form-control-sm "
									value="${testDataMain.inDate}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});" />
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
					<div class="form-group row">
						<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
						 备注信息：
						</label>
						<div class="col-lg-8 col-md-8 ">
							<#form:textarea path="remarks" rows="4"  maxlength="255" class="form-control input-xxlarge "/>
						</div>
					</div>
				</div>
			</div>

			<div class="control-group">
				<div class="table-title">业务数据子表：</div>
				<div class="controls">
					<table id="contentTable" class="table table-head-fixed table-bordered table-hover" cellspacing="0" width="100%">
						<thead>
							<tr>
								<th class="hide"></th>
								<th>名称</th>
								<th>备注信息</th>
								<% if(hasPermi('test:testDataMain:edit')){ %>
									<th width="10"> </th>
								<%}%>
							</tr>
						</thead>
						<tbody id="testDataChildList">
						</tbody>
						<% if(hasPermi('test:testDataMain:edit')){ %>
							<tfoot>
								<tr><td colspan="4"><a href="javascript:" onclick="addRow('#testDataChildList', testDataChildRowIdx, testDataChildTpl);testDataChildRowIdx = testDataChildRowIdx + 1;" class="btn btn-sm btn-default"><i class="fa fa-plus"></i> 新增</a></td></tr>
							</tfoot>
						<%}%>
					</table>
				</div>
			</div>
		</div>

		<div class="box-footer">
			<div class="row">
				<div class="offset-md-2 col-md-10">
					<% if (hasPermi('test:testDataMain:edit')){ %>
						<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> 保 存</button>
					<% } %>
					<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="window.parent.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> 关 闭</button>
				</div>
			</div>
		</div>
	</#form:form>
</div>
<% } %>

<script type="text/javascript">
	$("#inputForm").validate({
		submitHandler: function(form){
			js.ajaxSubmitForm($(form), function(data){
				js.showMessage(data.message);
				if(data.result == 'true'){
					window.parent.closeCurrentTabPage(window.parent.refreshTab);
				}
			});
	    }
	});

	function addRow(list, idx, tpl, row){
		$(list).append(Mustache.render(tpl, {
			idx: idx, delBtn: true, row: row
		}));
		$(list+idx).find("select").each(function(){
			$(this).val($(this).attr("data-value"));
		});
		$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
			var ss = $(this).attr("data-value").split(',');
			for (var i=0; i<ss.length; i++){
				if($(this).val() == ss[i]){
					$(this).attr("checked","checked");
				}
			}
		});
	}
	
	function delRow(obj, prefix){
		var id = $(prefix+"_id");
		var delFlag = $(prefix+"_delFlag");
		if (id.val() == ""){
			$(obj).parent().parent().remove();
		}else if(delFlag.val() == "0"){
			delFlag.val("1");
			$(obj).html("&divide;").attr("title", "撤销删除");
			$(obj).parent().parent().addClass("error");
		}else if(delFlag.val() == "1"){
			delFlag.val("0");
			$(obj).html("&times;").attr("title", "删除");
			$(obj).parent().parent().removeClass("error");
		}
	}
</script>

<script type="text/template" id="testDataChildTpl">//<!--
	<tr id="testDataChildList{{idx}}">
		<td class="hide">
			<input id="testDataChildList{{idx}}_id" name="testDataChildList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
			<input id="testDataChildList{{idx}}_delFlag" name="testDataChildList[{{idx}}].delFlag" type="hidden" value="0"/>
		</td>
		<td>
			<input id="testDataChildList{{idx}}_name" name="testDataChildList[{{idx}}].name" type="text" value="{{row.name}}" maxlength="100" class="form-control input-small "/>
		</td>
		<td>
			<textarea id="testDataChildList{{idx}}_remarks" name="testDataChildList[{{idx}}].remarks" rows="4" maxlength="255" class="form-control input-small ">{{row.remarks}}</textarea>
		</td>
		<% if(hasPermi('test:testDataMain:edit')){ %>
			<td class="text-center" width="10">
				{{#delBtn}}<span class="close" onclick="delRow(this, '#testDataChildList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
			</td>
		<%}%>
	</tr>//-->
</script>

<script type="text/javascript">
	var testDataChildRowIdx = 0, testDataChildTpl = $("#testDataChildTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
	$(document).ready(function() {
		<% var testDataChildData = @JsonMapper.toJsonString(testDataMain.testDataChildList); %>
		var list = ${testDataChildData};
		for (var i=0; i<list.length; i++){
			addRow('#testDataChildList', testDataChildRowIdx, testDataChildTpl, list[i]);
			testDataChildRowIdx = testDataChildRowIdx + 1;
		}
	});
</script>

